<!DOCTYPE html>
<html>
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
<input type="hidden" id="username" th:value="${session.username}">
<div class="wrapper wrapper-content ">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <form class="form-horizontal m-t" id="signupForm">
                        <input th:value="${pid}" id="pid" name="pid" class="form-control" type="hidden">
                        <input th:value="${wid}" id="wid" name="wid" class="form-control" type="hidden">
                        <input th:value="${did}" id="did" name="did" class="form-control" type="hidden">
                        <input th:value="${visitdate}" id="visitdate" name="visitdate" class="form-control"
                               type="hidden">
                        <input th:value="${visitnoon}" id="visitnoon" name="visitnoon" class="form-control"
                               type="hidden">
                        <input th:value="${ordertime}" id="ordertime" name="ordertime" class="form-control"
                               type="hidden">
                        <input th:value="${state}" id="state" name="state" class="form-control" type="hidden">

                        <input id="serialnumber" name="serialnumber" class="form-control" type="hidden">
                        <input id="visittime" name="visittime" class="form-control" type="hidden">


                        <div class="form-group">
                            <div class="col-sm-6" th:each="item,ind: ${nsNums}">
                                <label>
                                    <input type="radio"
                                           name="temp"
                                           th:text="${'就诊序号'+(ind.index)+'--就诊时间：'+visitdate+'  '+nsNumsTime[ind.index]}"
                                           th:value="${ind.index}"
                                           th:onclick="${'selNum('+ind.index+','''+nsNumsTime[ind.index]+''')'}"
                                           th:disabled="${item != 0}"
                                    >
                                </label>
                            </div>
                        </div>


                        <div class="form-group">
                            <div class="col-sm-8 col-sm-offset-3">
                                <button type="submit" class="btn btn-primary">提交</button>
                            </div>
                        </div>

                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<div th:include="include::footer"></div>

<script>
    $().ready(function () {
        validateRule();
    });

    $.validator.setDefaults({
        submitHandler: function () {
            save();
        }
    });

    function save() {
        layer.confirm(
            '确定要预约么？<br /><hr />' +
            '预约信息核对<br />' +
            '姓名：'+$('#username').val()+'<br />' +
            '预约医生：医生2<br />' +
            '预约科室：中内科<br />' +
            '就诊时间：'+$('#visitdate').val()+' '+$('#visitnoon').val()+' '+$('#visittime').val()+'<br />' +
            '预约费用：10.00元<br />',
            {
            btn: ['确定', '取消']
        }, function () {
            $.ajax({
                cache: true,
                type: "POST",
                url: "/yygl/record/save",
                data: $('#signupForm').serialize(),// 你的formid
                async: false,
                error: function (request) {
                    parent.layer.alert("Connection error");
                },
                success: function (data) {
                    if (data.code == 0) {
                        parent.layer.msg("操作成功");
                        var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                        parent.layer.close(index);
                        parent.location.href='/yyyh/myRecord';
                    } else {
                        parent.layer.alert(data.msg)
                    }

                }
            });
        })


    }

    function validateRule() {
        var icon = "<i class='fa fa-times-circle'></i> ";
        $("#signupForm").validate({
            rules: {
                name: {
                    required: true
                }
            },
            messages: {
                name: {
                    required: icon + "请输入姓名"
                }
            }
        })
    }

    function selNum(xuhao,date){
        $('#serialnumber').val(xuhao);
        $('#visittime').val(date);
    }
</script>
</body>
</html>
